/*
* Copyright (c) 2007 by Kirill Kolodyazhniy.
* See the file "license.terms" for information on usage and redistribution.
*/

#include "subentity.h"
#include "entity.h"
#include "graphic.h"
#include "mesh.h"

namespace Engine
{

	/**********************************************************************************************************/
	SubEntity::SubEntity(WeakPtr<SubMesh> subMesh, Entity* parent)
		:m_subMesh(subMesh)
		,m_parent(parent)
	{
		m_renderData = Graphic::GetSingleton().GetRenderSystem()->CreateRenderData(m_subMesh->GetFaceCount(), m_parent->GetMesh()->GetVertexCount(), m_parent->GetMesh()->GetVertexDeclaration(), subMesh->GetIndexData(),m_parent->GetMesh()->GetVertexData());
	}
	/**********************************************************************************************************/
	SubEntity::~SubEntity()
	{
	}
	/**********************************************************************************************************/
	const MaterialPtr SubEntity::GetMaterial(void) const
	{
		return m_subMesh->GetMaterial();
	}
	/**********************************************************************************************************/
	RenderDataPtr SubEntity::GetRenderData() const
	{
		return m_renderData;
	}
	/**********************************************************************************************************/
	const Matrix4<REAL>& SubEntity::GetWorldTransform() const
	{
		return m_parent->GetParentNode()->GetDerivedTransform();
	}
	/**********************************************************************************************************/
	const HardWareBufferPtr SubEntity::GetVertexData() const
	{
		return m_parent->GetMesh()->GetVertexData();
	}
	/**********************************************************************************************************/
	const HardWareBufferPtr SubEntity::GetIndexData() const
	{
		return m_subMesh->GetIndexData();
	}
	/**********************************************************************************************************/
	const VertexDeclarationPtr SubEntity::GetVertexDeclaration() const
	{
		return m_parent->GetMesh()->GetVertexDeclaration();
	}
	/**********************************************************************************************************/
}
